import {nextTick} from 'vue';
import {Router} from 'vue-router';

export const beforeEach = (router: Router) => {
  // 路由前置守卫
  router.beforeEach((to, from, next) => {
    if (to.meta.title) {
      //判断是否有标题
      document.title = to.meta.title as string;
    }
    next(); //执行进入路由，如果不写就不会进入目标页
  });
};

export const afterEach = (router: Router) => {
  // 路由后置钩子
  router.afterEach(() => {
    nextTick(() => {
      const bodyDom = document.querySelector('body')!;
      window.top?.postMessage({code: 211, iframeTag: location.href.replace(location.origin, ''), scrollHeight: bodyDom.scrollHeight}, '*');
    });
  });
};
